{ pkgs ? import <nixpkgs> {} }:

with pkgs;

let

  # https://nixos.org/nixpkgs/manual/#sec-emacs-config

  myEmacs = emacsPackagesNg.emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [
    plantuml-mode
  ]));

  emacsExtraConfig = writeText "emacs-org-config.el" ''
    (setq org-plantuml-jar-path "${plantuml}/lib/plantuml.jar"
          plantuml-jar-path "${plantuml}/lib/plantuml.jar"
          org-ditaa-jar-path "${ditaa}/lib/ditaa.jar")

    ;; active Org-babel languages
    (org-babel-do-load-languages
     'org-babel-load-languages
     '((plantuml . t)
       (ditaa . t)))
  '';

in

mkShell {

  # Launch emacs with the additional configuration.
  shellHook = ''
    exec ${myEmacs}/bin/emacs --load ${emacsExtraConfig}
  '';

  buildInputs = [
    openjdk8
  ];

}
